package modellayer;

import java.util.ArrayList;

public class Person
{
	private String name;
	private String address;
	private String postal;
	private String city;
	private String phone;
	private ArrayList<Loan> loans;

	/**
	 * the constructor of class Person
	 * @param name String 
	 * @param address String
	 * @param postal String
	 * @param city String
	 * @param phone String
	 */	
	public Person(String name, String address, String postal, String city, String phone)
	{
		this.name = name;
		this.address = address;
		this.postal = postal;
		this.city = city;
		this.phone = phone;
		loans = new ArrayList<Loan>();
	}

	/**
	 * @param l Loan
	 * add a Loan l to the arraylist loans
	 */	
	public void addLoan(Loan l)
	{
		loans.add(l);		
	}

	/**
	 * @param i int
	 * removes the object at index i from arraylist loans
	 */
	public void removeLoan(int i)
	{
		loans.remove(i);
	}

	/**
	 * @return loans ArrayList<Loan>
	 */
	public ArrayList<Loan> getLoan()
	{
		return loans;
	}

	/**
	 * returns the Loan based on id
	 * @param id int
	 * @return returnLoan Loan
	 */

	public Loan findLoan(int id)
	{
		Loan returnLoan = null;
		boolean found = false;
		int size = loans.size();
		for(int i = 0;  i < size && !found;i++)
		{
			if(loans.get(i).getId() == id)
			{
				returnLoan = loans.get(i);
				found = true;
			}
		}
		return returnLoan;
	}

	/**
	 * @return the name
	 */
	public String getName()
	{
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) 
	{
		this.name = name;
	}
	/**
	 * @return the address
	 */
	public String getAddress() 
	{
		return address;
	}

	/**
	 * @param address the address to set
	 */
	public void setAddress(String address) 
	{
		this.address = address;
	}

	/**
	 * @return the postalCode
	 */
	public String getPostal() 
	{		
		return postal;
	}

	/**
	 * @param postalCode the postalCode to set
	 */
	public void setPostal(String postal) 
	{
		this.postal = postal;
	}

	/**
	 * @return the city
	 */
	public String getCity() 
	{
		return city;
	}

	/**
	 * @param city the city to set
	 */
	public void setCity(String city) 
	{
		this.city = city;
	}

	/**
	 * @return the phone
	 */
	public String getPhone() 
	{
		return phone;
	}

	/**
	 * @param phone the phone to set
	 */
	public void setPhone(String phone) 
	{
		this.phone = phone;
	}

}
